package io.jft.doll.room.dao

import android.arch.lifecycle.LiveData
import android.arch.persistence.room.*
import io.jft.doll.room.entity.common.RoomCEntity

@Dao
interface RoomDao {
    companion object {
        const val TABLE_NAME = "RoomCEntity"
    }

    //获取房间同步
    @Query("SELECT * FROM $TABLE_NAME WHERE id=:id LIMIT 1")
    fun getRoomSync(id: String): RoomCEntity?

    //获取预约的房间同步
    @Query("SELECT * FROM $TABLE_NAME WHERE isAppointment=1 LIMIT 1")
    fun getAppointmentRoom(): RoomCEntity?

    //获取房间
    @Query("SELECT * FROM $TABLE_NAME WHERE id=:id LIMIT 1")
    fun getRoom(id: String): LiveData<RoomCEntity?>

    //获取指定列表(组的房间
    @Query("SELECT * FROM $TABLE_NAME WHERE groupId=:groupId LIMIT :limit")
    fun getGroupRoomList(groupId: String, limit: Int): LiveData<List<RoomCEntity>?>

    //更新房间
    @Update(onConflict = OnConflictStrategy.REPLACE)
    fun updateRoom(vararg room: RoomCEntity)

    //插入房间
    @Insert(onConflict = OnConflictStrategy.IGNORE)
    fun insertRoom(vararg room: RoomCEntity)

    @Query("DELETE FROM $TABLE_NAME")
    fun nukeTable()
}